package com.hatricks.is.invokedynamic;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;

/**
 * @packageName: com.hatricks.is.invokedynamic
 * @className: FooMethodHandle
 * @author: yanyuhui y568821795@outlook.com
 * @date: 2024-12-10 17:16
 * @description:
 */
@SuppressWarnings("CallToPrintStackTrace")
public class FooMethodHandle {
    public static void bar(Object o) {
        new Exception().printStackTrace();
    }

    public static void main(String[] args) throws Throwable {
        MethodHandles.Lookup l = MethodHandles.lookup();
        MethodType t = MethodType.methodType(void.class, Object.class);
        MethodHandle mh = l.findStatic(FooMethodHandle.class, "bar", t);
        // 添加jvm参数用来适配全部调用栈帧
        // -XX:+UnlockDiagnosticVMOptions -XX:+ShowHiddenFrames
        mh.invokeExact(new Object());
    }
}
